//package com.jiezhuo.utils;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.jiezhuo.entity.IotNodeInfo;
//import com.jiezhuo.entity.IotSensorInfo;
//import com.jiezhuo.mapper.iot.IotNodeInfoMapper;
//import com.jiezhuo.mapper.iot.IotSensorInfoMapper;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//
///**
// * @Author shuaigesheng
// * @Date 2022 10 26 15 33
// **/
//@Component
//@Slf4j
//public class ProtocolUtil {
//
//    private static final String HOST = "IOT_SERVER_LPM:control";
//
//    @Autowired
//    private IotSensorInfoMapper iotSensorInfoMapper;
//
//    @Autowired
//    private IotNodeInfoMapper iotNodeInfoMapper;
//
//    private static ProtocolUtil protocolUtil;
//
//    @PostConstruct
//    public void init() {
//        protocolUtil = this;
//        protocolUtil.iotSensorInfoMapper = this.iotSensorInfoMapper;
//        protocolUtil.iotNodeInfoMapper = this.iotNodeInfoMapper;
//    }
//
//    /**
//     * 开关控制
//     *
//     * @param id 传感器id
//     * @return
//     */
//    public static String sendControlSensorCommand(int id, Double sdata) {
//        StringBuffer stringBuffer = new StringBuffer();
//        QueryWrapper<IotSensorInfo> wrapper = new QueryWrapper<>();
//        wrapper.eq("id", id);
//        IotSensorInfo iotSensorInfo = protocolUtil.iotSensorInfoMapper.selectOne(wrapper);
//        IotNodeInfo iotNodeInfo = protocolUtil.iotNodeInfoMapper.selectById(iotSensorInfo.getNodeId());
//        stringBuffer.append(HOST + ",");
//        stringBuffer.append(iotNodeInfo.getDeviceCode() + ",");
//        stringBuffer.append(iotSensorInfo.getSensorDeviceId() + ",");
//        stringBuffer.append(iotSensorInfo.getPortId() + ",");
//        stringBuffer.append(sdata + ",");
//        if (StringUtils.isNotEmpty(iotSensorInfo.getInfos())) {
//            stringBuffer.append(iotSensorInfo.getInfos());
//        } else {
//            stringBuffer.append("{}");
//        }
//        return stringBuffer.toString();
//    }
//}
